<?php
namespace app\index\controller;
use think\Controller;
use app\index\model\Cate;
class Common extends Controller
{
	//初始化方法
     public function _initialize()
    {
      //当前位置
      if(input('cateid')){
        $this->getPos(input('cateid'));
      }elseif(input('artid')){
        $article=db('article')->field('cateid')->find(input('artid'));
        $cateid=$article['cateid'];
        $this->getPos($cateid);
      }
        // 网站配置项       
        $this->getConf();
       //网站导航栏目
       $this->getAllCates();
    }

    public function getAllCates(){
      $cateres=db('cate')->where('pid',0)->select();
      
      foreach ($cateres as $k => $v) {
          $children=db('cate')->where('pid',$v['id'])->select();
          if($children){
            $cateres[$k]['children']=$children;
          }else{
            $cateres[$k]['children']=0;
          }
      }
      return $this->assign('cateres',$cateres);
    }

    public function getConf(){
        //配置项模型初始化
       $conf=new \app\index\model\Conf();
       $_confres=$conf->getAllconf();
       //dump($_confres);die;
       $confres=array();
       foreach ($_confres as $k => $v) {
          //$confres[$v['enname']]=$v['cnname']; 
          $confres[$v['enname']]=$v['value'];

       }
      //dump($confres);die;
       $this->assign('confres',$confres);
    }

    public function getPos($cateid)
    {
      $cate=new Cate();
      $postArr=$cate->getparentid($cateid);
      //dump($postArr);die;
      $this->assign('postArr',$postArr);
    }
}
